import Search from "./search.vue";

export default {
    extends: Search,
    created() {
        console.log(this.code ,'code')
        if (this.code === "orderInProcess" || this.code === "patent" || this.code === 'canBeInvoice' || this.code === 'alreadyInvoice') {
            this.$emit("getAllAgent");
        }
    },
    methods: {
        addFilterCondition(item) {
            console.log(item, 'item')
            let filterItem = {
                value: "",
                label: item.label,
                parameter: item.prop || item.parameter,
                key: Date.now()
            };

            if (this.conditionForma.condition.length > 0) {
                let conditionlabels = [];
                for (let i = 0; i < this.conditionForma.condition.length; i++) {
                    conditionlabels.push(
                        this.conditionForma.condition[i].label
                    );
                }
                let Check = conditionlabels.indexOf(item.label);
                Check == -1
                    ? this.conditionForma.condition.push(filterItem)
                    : this.$message.error("请勿重复添加");
            } else {
                this.conditionForma.condition.push(filterItem);
            }

            this.showFilterCondition = false;
        },

        submitsearch(formName) {
            // this.$emit("searchParams");

            // console.log(this.conditionForma, "this.conditionForm.condition");

            // let arr = this.conditionForma.condition

            // for (const item of arr) {

            //     if(item.parameter === "agent_id") {
            //         this.formAgent.name = item.value
            //     }

            // }

            let params = {
                condition: this.conditionForma.condition,
                formAgent: this.formAgent,
                submitTime: this.submitTime,
                updatedTime: this.updatedTime,
                formProcess: this.formProcess,
                ticket_at: this.ticket_at,
                refund_at: this.refund_at
            }

            console.log(params, '-----params-----')

            this.$emit("searchParams", params);

        },

        removeDomain(item) {
            this.formAgent = {}
            this.submitTime = []
            this.formProcess = {}
            this.$emit("removeDomain", item);
        },

        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.conditionForma.condition = [];
            this.showFilterCondition = false;
            this.showFilter = false;

            console.log('开始调用父函数')
            this.$emit("reset");
        },

        handleSelect1(item) {
            this.formAgent.id = item.id;
            this.$refs["conditionForma"].clearValidate();
        },
        handleSelect2(item) {
            this.formProcess.id = item.id
            this.$refs['conditionForma'].clearValidate()
        },

        changInput() {
            this.$refs["conditionForma"].clearValidate();
        },

        // 代理人模糊匹配
        querySearch1(queryString, cb) {
            console.log(this.restaurantsm, "this.restaurants");
            let that = this;
            let restaurants = this.restaurants;
            let results = [];
            if (restaurants.length > 0) {
                results = queryString
                    ? restaurants.filter(that.createFilter(queryString))
                    : restaurants;
            }
            // 调用 callback 返回建议列表的数据
            cb(results);
        },

        // 流程模糊匹配
        querySearch2(queryString, cb) {
            let that = this;
            let restaurants = this.restaurants2;
            let results = [];
            if (restaurants.length > 0) {
                results = queryString
                    ? restaurants.filter(that.createFilter(queryString))
                    : restaurants;
            }
            // 调用 callback 返回建议列表的数据
            cb(results);
        },

        // getAllAgent() {
        //     console.log("123 getAllAgent");
        //     this.$emit("getAllAgent");
        // },

        createFilter(queryString) {
            return restaurant => {
                return (
                    restaurant.value
                        .toLowerCase()
                        .indexOf(queryString.toLowerCase()) >= 0
                );
            };
        }
    }
};
